
package com.prim.update.listener;

import android.content.DialogInterface;

import com.prim.update.interfaces.IUpdateExplorer;

public class DefaultPromptClickListener implements DialogInterface.OnClickListener {
    private final IUpdateExplorer mAgent;
    private final boolean mIsAutoDismiss;

    public DefaultPromptClickListener(IUpdateExplorer agent, boolean isAutoDismiss) {
        mAgent = agent;
        mIsAutoDismiss = isAutoDismiss;
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                mAgent.setCancleUpdate(false);
                mAgent.update();
                break;
            case DialogInterface.BUTTON_NEUTRAL:
                if (mAgent.getBuilder().isIgnorable) {
                    mAgent.ignore();
                } else {
                    mAgent.stop();
                    dialog.dismiss();
                }
                break;
            case DialogInterface.BUTTON_NEGATIVE:
                mAgent.setCancleUpdate(true);
                mAgent.update();
                break;
        }
        if (mIsAutoDismiss) {
            dialog.dismiss();
        }
    }
}